package de.hsf.bp.netdoc.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JDialog;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

import java.awt.event.ContainerAdapter;
import java.awt.event.ContainerEvent;

/**
 * In dieser Klasse wird die MenuBar erzeugt und verwaltet
 * 
 * @author Markus
 *
 */

public class MenuBar extends JMenuBar {

	GuiView myGUI;
	
	public MenuBar(GuiView gui){
		myGUI = gui;
		
		/**
		 * Copy & Paste vom WindowBuilder
		 * menuBar.add wurde zu add, da diese Klasse
		 * von JMenuBar erbt und nicht in einem JFrame liegt
		 */
		
		JMenu mnProject = new JMenu("Project");
		add(mnProject);
		
		JMenuItem mntmNewProject = new JMenuItem("New Project");
		mntmNewProject.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				NewProject JDialog;
				JDialog = new NewProject();
				JDialog.show();	
				JDialog.setVisible(true);
				JDialog.setLocationRelativeTo(myGUI);
				JDialog.setModalityType(null);
				JDialog.setModal(true);
				
			}
		});
		mnProject.add(mntmNewProject);
		
		JMenuItem mnLoadProject = new JMenuItem("Load Project");
		mnProject.add(mnLoadProject);
		
		JMenuItem mntmSaveProject = new JMenuItem("Save Project");
		mnProject.add(mntmSaveProject);
		
		JMenuItem mntmSaveAs = new JMenuItem("Save As...");
		mnProject.add(mntmSaveAs);
		
		JMenuItem mntmProperties = new JMenuItem("Properties");
		mnProject.add(mntmProperties);
		
		JMenuItem mntmQuit = new JMenuItem("Quit");
		mnProject.add(mntmQuit);
		
		JMenu mnComponents = new JMenu("Components");
		add(mnComponents);
		
		JMenuItem mntmViewEdit = new JMenuItem("View / Edit Components");
		mntmViewEdit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				myGUI.changePanel(CardNames.COMPONENTS);
			}
		});
		mnComponents.add(mntmViewEdit);
		
		JMenuItem mntmEditProperties = new JMenuItem("Edit Properties");
		mnComponents.add(mntmEditProperties);
		
		JMenuItem mntmViewConnections = new JMenuItem("View Connections");
		mnComponents.add(mntmViewConnections);
		
		JMenu mnActions = new JMenu("Actions");
		add(mnActions);
		
		JMenuItem mntmGetComponentInfo = new JMenuItem("Get Component Info");
		mnActions.add(mntmGetComponentInfo);
		
		JMenuItem mntmShowRoute = new JMenuItem("Show Route");
		mnActions.add(mntmShowRoute);
		
		JMenu mnAbout = new JMenu("About");
		add(mnAbout);
		
		JMenu mnHelp = new JMenu("Help");
		mnAbout.add(mnHelp);
		
		JMenuItem mntmNetworkModel = new JMenuItem("Network Model");
		mntmNetworkModel.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				myGUI.changePanel(CardNames.HELPPAGE);
				
			}
		});
		mnHelp.add(mntmNetworkModel);
		
		JMenuItem mntmAbout = new JMenuItem("About...");
		mnAbout.add(mntmAbout);
	}
}
